package org.gongzhen.HomeMapper;

import lombok.Data;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.gongzhen.Save;

@Mapper
public interface PostCollectionMapper {

    /**
     * 查询用户是否已收藏帖子
     */
    @Select("select * from save where user_id = #{userId} and post_id = #{postId}")
    Save getByUserIdAndPostId(Integer postId, Integer userId);

    @Delete("delete from save where id = #{id}")
    void deleteById(Integer id);

    /**
     * 绑定用户和帖子关系
     * @param save
     */
    @Insert("insert into save(user_id, post_id, create_time) values(#{userId}, #{postId}, #{createTime})")
    void collection(Save save);
}
